package com.keke.cptt.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.keke.cptt.sercive.CpttService;
import com.keke.utils.SystemException;

@WebServlet("/api/UpdateCptt")
public class UpdateCptt extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static CpttService service = new CpttService();

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		return;
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String data = (String) req.getAttribute("data");
		
		System.out.println(data);
		PrintWriter out = resp.getWriter();
		String info;
		String type = "warning";
		try {
	        info = service.updateCptt(data);
			type = "success";
		} catch (SystemException e) {
			info = e.toString().split(": ")[1];
		}
		out.print(" {\"isOk\":true,"
	       		+ "\"info\":\""+info+"\","
	       		+ "\"type\":\""+type+"\"}");
	}
}